package com.zeei.ems.meet.controller;

import com.github.pagehelper.PageInfo;
import com.zeei.ems.base.constant.GlobalConstant;
import com.zeei.ems.base.controller.BasicController;
import com.zeei.ems.base.page.PageParamVO;
import com.zeei.ems.base.result.ResultBasicVO;
import com.zeei.ems.base.result.ResultDataVO;
import com.zeei.ems.base.result.ResultRowsVO;
import com.zeei.ems.base.tree.TreeNodeVO;
import com.zeei.ems.base.util.StringUtil;
import com.zeei.ems.meet.model.PointVideoVO;
import com.zeei.ems.meet.model.VideoVO;
import com.zeei.ems.meet.model.vo.VideoParam;
import com.zeei.ems.meet.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "视频管理接口")
@RestController
@RequestMapping("/ems/video")
public class VideoController extends BasicController {
    @Autowired
    VideoService videoService;

    /**
     * 分页查询视频列表
     * @param videoParam 视频信息
     * @return 返回视频信息列表
     */
    @ApiOperation(value = "分页查询视频信息列表")
    @PostMapping("/page/list")
    public ResultRowsVO<VideoVO> listVideo(PageParamVO page,
                                                      @RequestBody VideoParam videoParam){
        PageInfo<VideoVO> videoPageInfo = videoService.listVideo(page, videoParam);
        return this.createResultRowsVO(videoPageInfo, GlobalConstant.SUCCEED, "");
    }

    /**
     * 查询视频信息列表
     * @param videoParam 视频信息
     * @return 返回视频信息列表
     */
    @ApiOperation(value = "查询视频信息列表")
    @PostMapping("/list")
    public ResultRowsVO<VideoVO> listVideo(@RequestBody VideoParam videoParam){
        List<VideoVO> videoList = videoService.listVideo(videoParam);
        return this.createResultRowsVO(videoList, GlobalConstant.SUCCEED, videoList.size());
    }

    @ApiOperation(value = "查询视频信息列表")
    @PostMapping("/point/tree")
    public ResultRowsVO<TreeNodeVO<PointVideoVO>> getPointVideoTree(){
        List<TreeNodeVO<PointVideoVO>> pointVideoList = videoService.pointVideoList();
        return this.createResultRowsVO(pointVideoList, true, null, pointVideoList.size());
    }

    /**
     * 查询视频信息
     * @return 返回视频信息
     */
    @ApiOperation(value = "查询视频信息")
    @PostMapping("/get")
    public ResultDataVO<VideoVO> getVideo(){
        VideoVO video = videoService.getVideoConfig();
        return this.createResultDataVO(video, GlobalConstant.SUCCEED);
    }

    /**
     * 新增视频信息
     * @param video 视频信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "新增视频信息")
    @PostMapping("/add")
    public ResultBasicVO addVideo(@RequestBody VideoVO video){
        Boolean result = videoService.addVideo(video);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 更新视频信息
     * @param video 视频信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "更新视频信息")
    @PostMapping("/update")
    public ResultBasicVO  updateVideo(@RequestBody VideoVO video){
        Boolean result = videoService.updateVideo(video);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 删除视频信息
     * @param videoIdList 视频ID集合
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "删除视频信息")
    @PostMapping("/delete")
    public ResultBasicVO  deleteVideo(@RequestBody List<Integer> videoIdList){
        Boolean result = videoService.deleteVideo(videoIdList);
        return this.createResultBasicVO(result, StringUtil.empty());
    }
}
